package com.ourgame.tankgame.tank;

import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.ourgame.tankgame.control.BaseControlSystem;
import com.ourgame.tankgame.control.BaseMoveSystem;
import com.ourgame.tankgame.control.BaseWeaponSystem;
import com.ourgame.tankgame.control.ControlSystem;
import com.ourgame.tankgame.control.MoveSystem;
import com.ourgame.tankgame.control.WeaponSystem;
import com.ourgame.tankgame.object.TankGameObject;
import gameutil.Role;

/**
 * 所有坦克的基类
 * @author echoff
 */
public class Tank extends TankGameObject {

    //基本参数
    protected float tankMaxSpeed;
    protected float tankMass;
    protected float tankWeight;
    protected float tankArmoured;
    protected float tankHorsepower;
    protected String tankName;
    private Role tankRole;
    //外观
    private Node tankNode = new Node();
    //系统
    private MoveSystem moveSystem;  //发动机系统
    private WeaponSystem weaponSystem;  //武器系统
    private ControlSystem controlSystem;  //控制系统

    public Tank(Spatial shell) {
        super(shell);
        tankName = "tank";
        setName(tankName);
//        tankNode.setName("tankNode");
//        tankNode.attachChild(shell);

        moveSystem = new BaseMoveSystem();
        weaponSystem = new BaseWeaponSystem();
        controlSystem = new BaseControlSystem();
    }

    //********************************************************
    //*      get、set 区域                                    *
    //********************************************************
    /**
     * 查询坦克身份
     * @return the tankRole
     */
    public Role getTankRole() {
        return tankRole;
    }

    public void setTankRole(Role role) {
        this.tankRole = role;
    }

    /**
     * 查询坦克信息
     * @return tankInfo
     */
    public String getTankInfo() {
        return tankName;
    }

    public float getTankArmoured() {
        return tankArmoured;
    }

    public void setTankArmoured(float tankArmoured) {
        this.tankArmoured = tankArmoured;
    }

    public float getTankHorsepower() {
        return tankHorsepower;
    }

    public void setTankHorsepower(float tankHorsepower) {
        this.tankHorsepower = tankHorsepower;
    }

    public float getTankMass() {
        return tankMass;
    }

    public void setTankMass(float tankMass) {
        this.tankMass = tankMass;
    }

    public float getTankMaxSpeed() {
        return tankMaxSpeed;
    }

    public void setTankMaxSpeed(float tankMaxSpeed) {
        this.tankMaxSpeed = tankMaxSpeed;
    }

    public float getTankWeight() {
        return tankWeight;
    }

    public void setTankWeight(float tankWeight) {
        this.tankWeight = tankWeight;
    }

    /**
     * @return the shell
     */
//    public Spatial getShell() {
//        return tankNode.getChild(tankName);
//    }
    /**
     * 
     * @return tankNode
     */
//    public Node getTankNode() {
//        return tankNode;
//    }
    /**
     * @param shell the shell to set
     * @deprecated 
     */
    public void setShell(Spatial shell) {
        int index = tankNode.detachChildNamed(tankName);
        if (index < 0) {
            //TODO throw exeception
            return;
        }
        tankNode.attachChild(shell);
    }

    /**
     * @return the moveSystem
     */
    public MoveSystem getMoveSystem() {
        return moveSystem;
    }

    /**
     * @param moveSystem the moveSystem to set
     */
    public void setMoveSystem(MoveSystem moveSystem) {
        this.moveSystem = moveSystem;
    }

    /**
     * @return the weaponSystem
     */
    public WeaponSystem getWeaponSystem() {
        return weaponSystem;
    }

    /**
     * @param weaponSystem the weaponSystem to set
     */
    public void setWeaponSystem(WeaponSystem weaponSystem) {
        this.weaponSystem = weaponSystem;
    }

    /**
     * @return the controlSystem
     */
    public ControlSystem getControlSystem() {
        return controlSystem;
    }

    /**
     * @param controlSystem the controlSystem to set
     */
    public void setControlSystem(ControlSystem controlSystem) {
        this.controlSystem = controlSystem;
//        setupModule();
    }

    //********************************************************
    //*      功能方法区域                                     *
    //********************************************************
    public void setupModule() {
//        if(tankNode != null) {
            /*
         * 添加三大系统
         */
        addControl(controlSystem);
//            shell.addControl(weaponSystem);
//            shell.addControl(moveSystem);
            /*
         * 使controlSystem来控制另外的系统
         */
        controlSystem.addWeaponSystem(weaponSystem);
        controlSystem.addMoveSystem(moveSystem);
//            controlSystem.setWeaponSystem(weaponSystem);
//            controlSystem.setMoveSystem(moveSystem);
            /*
         * 初始化系统
         */
        controlSystem.init();

//        }
    }

    /**
     * 装备移动系统
     * @return 
     */
    public boolean equipMoveSystem() {
//        TODO:装备移动系统。
//        this.moveSystem = 
        return false;
    }

    /**
     * 装备武器系统
     * @return 
     */
    public boolean equipWeaponSystem() {
//        TODO:装备武器系统。
//        this.weaponSystem=
        return false;
    }

    /**
     * 装备控制系统
     * @return 
     */
    public boolean equipControlSystem() {
//        TODO:装备控制系统。
//        this.controlSystem=
        return false;
    }
}